package com.atzexu.service.impl;

import com.atzexu.domain.Assignment;
import com.atzexu.domain.dto.FindNotWorkDTO;
import com.atzexu.domain.dto.ShowWorkDTO;
import com.atzexu.domain.vo.NotWorkStudentVo;
import com.atzexu.domain.vo.UserWorkVo;
import com.atzexu.mapper.AssignmentMapper;
import com.atzexu.service.AssignmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class AssignmentServiceImpl implements AssignmentService {

    @Autowired
    private AssignmentMapper assignmentMapper;

    /**
     * 发布作业
     *
     * @param assignment
     * @return
     */
    @Override
    public boolean publishWork(@RequestBody Assignment assignment) {
        // 获取session中登录的userId
        return assignmentMapper.publishWork(assignment) > 0;
    }

    /**
     * 作业展示
     *
     * @param showWorkDTO
     * @return
     */
    @Override
    public List<UserWorkVo> showWorks(ShowWorkDTO showWorkDTO) {
        List<UserWorkVo> list = assignmentMapper.showWorks(showWorkDTO);
        System.out.println(list);
        return list;
    }

    /**
     * 查询时间段未提交作业的学生以及次数
     *
     * @param findNotWorkDTO
     * @return
     */
    @Override
    public List<NotWorkStudentVo> findNotWorkByTime(FindNotWorkDTO findNotWorkDTO) {
        List<NotWorkStudentVo> list = assignmentMapper.findNotWorkByTime(findNotWorkDTO);
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getUserId() == null && list.get(i).getName() == null) {
                list.remove(i);
            }
        }
        return list;
    }
}
